package NetEase;

import java.util.*;

public class Main_0904_4 {
    //求n的因子个数
    static int getYZ(int n){
        if(n==0) return 0;
        if (n<=1){
            return 1;
        }
        int s=0;
        for (int i = 1; i <=n ; i++) {
            s+=n/i;
        }
        int t=0;
        for (int i = 1; i < n; i++) {
            t+=(n-1)/i;
        }
        return s-t;
    }
    static int mod=1000000007;
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int[] weight = new int[n+1];
        //需要记录每个节点为根的子树中的权重乘积
        int[] Wsum=new int[n+1];
        for (int i = 1; i < n+1; i++) {
            weight[i]=cin.nextInt();
            Wsum[i]=weight[i];
        }
        int[] formNode=new int[n+1];
        for (int i = 0; i < n - 1; i++) {
            int from=cin.nextInt();
            int to=cin.nextInt();
            formNode[to]=from;
        }
        for (int i = 1; i <= n; i++) {
            int cur=weight[i];
            Queue<Integer> queue=new LinkedList<>();
            queue.offer(i);
            while (!queue.isEmpty()){
                int curNode=queue.poll();
                Wsum[formNode[curNode]]=(Wsum[formNode[curNode]]*cur)%mod;
                queue.offer(formNode[curNode]);

            }
        }
        int res=0;
        for (int sum:Wsum) {
            res+=getYZ(sum);
        }
        System.out.println(res);
    }
}
